unit GMedConfigFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, cxPC, cxControls, ExtCtrls, cxGraphics, cxTextEdit, cxMaskEdit,
  GForm, GConfigForm,
  cxDropDownEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, cxContainer,
  cxEdit, cxLabel, cxGroupBox;

type
  TfMedConfigFrame = class(TFrame)
    mainPanel: TPanel;
    pcMed: TcxPageControl;
    tsSpausdintuvai: TcxTabSheet;
    tsKiti: TcxTabSheet;
    tsPrekes: TcxTabSheet;
    cxLabel1: TcxLabel;
    cxLabel2: TcxLabel;
    cxLabel3: TcxLabel;
    cxLabel4: TcxLabel;
    ePRastai: TcxLookupComboBox;
    ePMediena: TcxLookupComboBox;
    ePParketas: TcxLookupComboBox;
    ePGrindjuostes: TcxLookupComboBox;
    tsBendri: TcxTabSheet;
    cxGroupBox1: TcxGroupBox;
    cxLabel5: TcxLabel;
    cxLabel6: TcxLabel;
    cxGroupBox2: TcxGroupBox;
    cxLabel7: TcxLabel;
    cxLabel8: TcxLabel;
    eParkSandelis: TcxLookupComboBox;
    ePlintSandelis: TcxLookupComboBox;
    eMedSandelis: TcxLookupComboBox;
    eTarpSandelis: TcxLookupComboBox;
    Label17: TcxLabel;
    cbDefPrinter: TcxComboBox;
    cxLabel9: TcxLabel;
    cbLabelPrinter: TcxComboBox;
  private
    { Private declarations }
    parOK: boolean;

    MainForm: TGamaConfigForm;
    MainFormShow: TNotifyEvent;
    MainFormOKClick: TNotifyEvent;
    procedure FormShow(Sender: TObject);
    procedure OKClick(Sender: TObject);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  end;

implementation

{$R *.dfm}
uses
  Med_conf, med_dm, Tools, doktip, bendri, bendri_conf, Sandelys_dm, Printers;

constructor TfMedConfigFrame.Create(AOwner: TComponent);
var
  Form: TForm;
begin
  inherited;
  pcMed.ActivePage := tsBendri;

  Form := FindOwnerForm(AOwner);
  if Form is TGamaConfigForm then MainForm := TGamaConfigForm(Form)
  else MainForm := nil;

  if MainForm = nil then Exit;

  parOK := true;

  if Assigned(MainForm.OnShow) then 
    MainFormShow := MainForm.OnShow
  else
    MainFormShow := nil;
  MainForm.OnShow := FormShow;

  if Assigned(MainForm.GamaOK.OnClick) then
    MainFormOKClick := MainForm.GamaOK.OnClick
  else
    MainFormOKClick := nil;
  MainForm.GamaOK.OnClick := OKClick;

end;

procedure TfMedConfigFrame.FormShow(Sender: TObject);
var
  i: integer;
  iSk: integer;
begin
  if Assigned(MainFormShow) then MainFormShow(Sender);
  with dmMed do begin
    ePRastai.EditValue := MedConfigParam.MedPRastai;
    ePMediena.EditValue := MedConfigParam.MedPMediena;
    ePParketas.EditValue := MedConfigParam.MedPParketas;
    ePGrindjuostes.EditValue := MedConfigParam.MedPGrindjuostes;

    eMedSandelis.EditValue := MedConfigParam.MedSandelis;
    eTarpSandelis.EditValue := MedConfigParam.TarpSandelis;
    eParkSandelis.EditValue := MedConfigParam.ParkSandelis;
    ePlintSandelis.EditValue := MedConfigParam.PlintSandelis;

    // spausdinimas
    // pagrindinis printeris
    cbDefPrinter.Properties.Items.AddStrings(Printer.Printers);
    cbDefPrinter.ItemIndex := cbDefPrinter.Properties.Items.IndexOf(MedConfigParam.pDefPrinter);
    // lipduku printeris
    cbLabelPrinter.Properties.Items.AddStrings(Printer.Printers);
    cbLabelPrinter.ItemIndex := cbDefPrinter.Properties.Items.IndexOf(MedConfigParam.pLabelPrinter);

  end // with
end;


procedure TfMedConfigFrame.OKClick(Sender: TObject);
var
  i: integer;
begin
  if not parOK then begin
    Beep;
    MainForm.ModalResult := 0;
    Exit;
  end;
  //
  with dmMed do begin
    MedConfigParam.MedPRastai := ePRastai.EditValue;
    MedConfigParam.MedPMediena := ePMediena.EditValue;
    MedConfigParam.MedPParketas := ePParketas.EditValue;
    MedConfigParam.MedPGrindjuostes := ePGrindjuostes.EditValue;

    MedConfigParam.MedSandelis := eMedSandelis.EditValue;
    MedConfigParam.TarpSandelis := eTarpSandelis.EditValue;
    MedConfigParam.ParkSandelis := eParkSandelis.EditValue;
    MedConfigParam.PlintSandelis := ePlintSandelis.EditValue;

    MedConfigParam.pDefPrinter := cbDefPrinter.Text;
    MedConfigParam.pLabelPrinter := cbLabelPrinter.Text;

    MedConfigParam.Save;

    //dmEKA.Reconfigure;
  end;
  //
  if Assigned(MainFormOKClick) then MainFormOKClick(Sender);
end;

end.
